#ifndef __THREAD_H__
#define __THREAD_H__

#include <pthread.h>
#include <functional>
#include <string>
using std::string;
using std::function;

namespace current_thread
{
extern __thread const char* name;
};//end of current_thread 

class Thread
{
    using ThreadCallback = function<void()>;
public:
    /* Thread(const ThreadCallback &cb); */
    Thread(ThreadCallback &&cb,string name = "wd thread");
    ~Thread();

    //线程的开始与结束
    void start();
    void stop();

private:
    //线程入口函数
    static void *threadFunc(void *arg);

private:
    string _name;
    pthread_t _thid;//线程id
    bool _isRunning;//标识线程是否在运行
    ThreadCallback _cb;//将需要执行的任务以回调函数的形式展现
};

#endif

